"""
The is doc
"""

from django.contrib.auth import get_user_model
from rest_framework import serializers

from rest_framework.serializers import ModelSerializer

from . import models


class AppAdminSer(ModelSerializer):
    class Meta:
        model = get_user_model()
        exclude = [
            # no use ignore
            "openid",
            "created_at",
            "deleted",
            "del_race",
            # django ignore
            "id",
            "password",
            "last_login",
            "is_superuser",
            "username",
            "first_name",
            "last_name",
            "email",
            "is_staff",
            "is_active",
            "date_joined",
            "groups",
            "user_permissions",
        ]


class WxUserSer(ModelSerializer):
    class Meta:
        model = models.WxUser
        exclude = [
            # no use ignore
            "openid",
            "created_at",
            "deleted",
            "del_race",
            # django ignore
            "id",
            "password",
            "last_login",
            "is_superuser",
            "username",
            "first_name",
            "last_name",
            "email",
            "is_staff",
            "is_active",
            "date_joined",
            "groups",
            "user_permissions",
        ]


class RechargePromotionSer(ModelSerializer):
    class Meta:
        model = models.RechargePromotion
        fields = [
            "uuid",
            "created_at",
            "user_uuid",
            "actual_payment",
            "score",
        ]


class WxUserRechargeRecordSer(ModelSerializer):
    user = serializers.SerializerMethodField()

    def get_user(self, obj):
        obj = models.WxUser.objects.filter(uuid=obj.user_uuid).first()
        return WxUserSer(obj).data

    class Meta:
        model = models.WxUserRemainMoneyRecord
        fields = [
            "uuid",
            "created_at",
            "user_uuid",
            "user",
            "remain_money",
            "actual_payment",
            "score",
            "consume",
            "shopping_uuid",
            "recharge_type",
        ]


class WxUserPaymentRecordSer(ModelSerializer):
    class Meta:
        model = models.WxUserPaymentRecord
        exclude = ["openid", "spbill_create_ip", "mch_id", "env_id", "service"]


class StoreGoodSer(ModelSerializer):
    """用户屏蔽进价"""

    class Meta:
        model = models.StoreGood
        exclude = [
            "id",
            "created_at",
            "del_race",
            "deleted",
            "purchase_price",
        ]


class SimpleStoreGoodSer(ModelSerializer):
    """用户屏蔽进价"""

    class Meta:
        model = models.StoreGood
        fields = [
            "uuid",
            "name",
            "price",
            "display_url",
            "limit_count",
            "total_sale_count",
        ]


class OwnerStoreGoodSer(ModelSerializer):
    """管理员可以看到进价"""

    class Meta:
        model = models.StoreGood
        fields = "__all__"


class StoreGoodCarContentSer(ModelSerializer):
    """用户购物车内容"""

    good = serializers.SerializerMethodField()

    def get_good(self, obj):
        obj = models.StoreGood.objects.filter(uuid=obj.good_uuid).first()
        return SimpleStoreGoodSer(obj).data

    class Meta:
        model = models.StoreGoodCarContent
        exclude = ["id", "created_at", "del_race", "deleted"]


class StoreGoodTypeSer(ModelSerializer):
    class Meta:
        model = models.StoreGoodType
        exclude = [
            "id",
            "created_at",
            "del_race",
            "deleted",
        ]


class StoreShoppingSer(ModelSerializer):
    """用户购物车内容"""

    content = serializers.SerializerMethodField()

    def get_content(self, obj):
        objs = models.StoreShoppingContent.objects.filter(shopping_uuid=obj.uuid)
        return StoreShoppingContentSer(objs, many=True).data

    class Meta:
        model = models.StoreShopping
        exclude = ["id", "created_at", "del_race", "deleted"]


class StoreShoppingContentSer(ModelSerializer):
    """用户购物车内容"""

    good = serializers.SerializerMethodField()

    def get_good(self, obj):
        obj = models.StoreGood.objects.filter(uuid=obj.good_uuid).first()
        return SimpleStoreGoodSer(obj).data

    class Meta:
        model = models.StoreShoppingContent
        exclude = ["id", "created_at", "del_race", "deleted"]
